<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/ckform.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath}/js/commons_date.js"></script>
    <script>

        var uname="";
        $(function () {
            loadData();
        });
        //首页
        function firstPage() {
            loadData(1,uname);
        }
        //上一页
        function prePage(currentPage) {
            if (currentPage-1<1){
                loadData(1,uname);
            }else{
                loadData(currentPage-1,uname);
            }
        }
        //下一页
        function nextPage(currentPage,totalPage) {
            if (currentPage+1>totalPage){
                loadData(totalPage,uname)
            }else{
                loadData(currentPage+1,uname);
            }
        }
        //尾页
        function lastPage(totalPage) {
            loadData(totalPage,uname);
        }
        function loadData(currentPage,uname) {
            $.ajax({
                url:"${pageContext.request.contextPath}/user/getAllUsers",
                type:"get",
                data:{"currentPage":currentPage,"uname":uname},
                dataType:"json",
                cache:false,
                success:function (rs) {
                    //情况列表数据
                    $("#tbody").empty();
                    $.each(rs.records,function (index,element) {
                        var newTr="<tr>\n" +
                            "           <td><a href=\"${pageContext.request.contextPath}/user/user_detail?uid="+element.uid+"\">"+element.uname+"</a></td>\n" +
                            "           <td>"+element.truename+"</td>\n" +
                            "           <td>"+element.email+"</td>\n" +
                            "           <td>"+get_date(element.utime)+"</td>\n" +
                            "           <td><a href=\"javascript:deleteUser("+element.uid+")\">注销</a></td>\n" +
                            "       </tr>";

                        $("#tbody").append(newTr);
                    });
                    $("#tfoot").empty();
                    var userTr="<tr>\n" +
                        "\t\t\t\t<td style=\"text-align: center\" colspan=\"5\">\n" +
                        "\t\t\t\t\t<a href=\"javascript:firstPage()\">首页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n" +
                        "\t\t\t\t\t<a href=\"javascript:prePage("+rs.currentPage+")\">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n" +
                        "\t\t\t\t\t<a href=\"javascript:nextPage("+rs.currentPage+","+rs.totalPage+")\">下一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n" +
                        "\t\t\t\t\t<a href=\"javascript:lastPage("+rs.totalPage+")\">尾页</a>\n" +
                        "\t\t\t\t</td>\n" +
                        "\t\t\t</tr>";

                    $("#tfoot").append(userTr);

                }
            })
        }

        function searchUser() {
            var uname=$("#uname").val();
            loadData(1,uname)

        }
        function deleteUser(uid) {
            $.ajax({
                url:"${pageContext.request.contextPath}/user/deleteUser",
                type:"post",
                data:{"uid":uid},
                dataType:"json",
                cache:false,
                success:function (rs) {
                    if (rs.status==200){
                        loadData();
                    }else{
                        alert(rs.msg);
                    }
                }
            })

        }

    </script>

    <style type="text/css">
        body {font-size: 20px;
            padding-bottom: 40px;
            background-color:#e9e7ef;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>

</head>
<body>

<form id="form1" class="form-inline definewidth m20" action="#" method="get">
     <font color="#777777"><strong>用户名：</strong></font>
    <input type="text" name="uname" id="uname" class="abc input-default " placeholder="请填写用户名" value="">&nbsp;&nbsp;
    <button type="button" class="btn btn-primary queryBtn" onclick="searchUser()">查询</button>
</form>

<table id="usertable" class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th>用户名</th>
        <th>真实姓名</th>
        <th>Email</th>
        <th>注册日期</th>
        <th>冻结账户</th>
     </tr>
    </thead>
    <tbody id="tbody">
    <%--存放行数据--%>

    </tbody>
    <tfoot id="tfoot">
    <%--存放行数据--%>

    </tfoot>

</table>

</body>
</html>